package persistence;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Classe para conexão do banco de dados
 * @author fabio
 *
 */
public class ConexaoBanco {
	public static final byte DATABASE_TYPE = 1; //Selecione 0 para Postgre e 1 para MySQL
	
	public static final String BD_POSTGRE = "org.postgresql.Driver";
	public static final String BD_MYSQL = "com.mysql.jdbc.Driver";
	
	public static final String LOGIN = "root";
	public static final String SENHA = "root";
	public static final String BD_NAME = "trabalhoDB";
	public static final int PORT = 3306;
	public static final String SERVER = "localhost";

	static {
		try {
			Class.forName(DATABASE_TYPE == 0 ? BD_POSTGRE:BD_MYSQL);
		} catch (ClassNotFoundException e) {
			System.out.println("Classe nao encontrada.");
			Logger.getLogger(ConexaoBanco.class.getName()).log(Level.SEVERE, null, e);
		}
	}
	
	//TODO Lembrar sempre de mudar essa maldita senha...
	public static Connection getConnection() throws SQLException {
		String URI = "jdbc:"+(DATABASE_TYPE == 0? "postgresql":"mysql")+"://"+SERVER+":"+PORT+"/"+BD_NAME;
		
		return DriverManager.getConnection(URI, LOGIN, SENHA);
	}
	
	
}